Skip to content

Refactor duplicated code patterns into shared utilities (scripts/util.js)#677

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782156321-refactor-shared-utils
Open

Refactor duplicated code patterns into shared utilities (scripts/util.js)#677
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1782156321-refactor-shared-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Extracts 10 duplicated code patterns from across the codebase into a new scripts/util.js shared utility file, reducing copy-paste duplication and lowering lint errors from 161 → 95 (net -66 errors).

What moved to scripts/util.js:

Utility Was duplicated in Purpose
encodeToBase64(str) / decodeFromBase64(str) leetcode.js (×4), gfg.js (×2) Wraps btoa(unescape(encodeURIComponent(str))) and reverse
githubRequest(method, url, token, data, cb) leetcode.js (×2), welcome.js (×2), popup.js (×1) Authenticated GitHub API XHR with Authorization + Accept headers
getSHA(stats, filePath) leetcode.js (×2), gfg.js (×1) Look up file SHA from stats object
checkElem(elem) leetcode.js elem && elem.length > 0 — now available to all content scripts
languages leetcode.js Language → file extension map, also used by gfg.js
convertToSlug(string) leetcode.js String slugification
createDefaultStats() leetcode.js { solved: 0, easy: 0, medium: 0, hard: 0, sha: {} }
setDisplayMode(mode) welcome.js (×8 inline toggles) Toggles hook_mode/commit_mode display
displayStats(stats) popup.js, welcome.js Renders solved/easy/medium/hard counts

Wiring:

  • manifest.json: scripts/util.js added before content scripts
  • popup.html / welcome.html: <script src="scripts/util.js"> added before page scripts
  • /* global ... */ directives added to consumer files for ESLint

Link to Devin session: https://app.devin.ai/sessions/14c9a3a6edd84c35a8f66db154eaa4a3
Requested by: @QasimWani

Extract 10 shared functions/constants into scripts/util.js:
- checkElem, encodeToBase64, decodeFromBase64: DOM/encoding helpers
- languages: language-to-extension map (was in leetcode.js)
- convertToSlug: string slugification (was in leetcode.js)
- getSHA, createDefaultStats: chrome.storage stat helpers
- githubRequest: authenticated GitHub API XHR wrapper
- setDisplayMode, displayStats: UI state helpers

Refactored across leetcode.js, gfg.js, popup.js, welcome.js.
Net reduction of 66 lint errors (202 -> 131, all remaining pre-existing).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@QasimWani QasimWani self-assigned this Jun 22, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant